package it.lovaex.scb.Cart;

import it.lovaex.scb.model.IItem;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class CartItem {

	private String description;
	private int quantity;
	private BigDecimal unitPrice;
	private BigDecimal discount;
	
	public CartItem(int quantity, IItem item, BigDecimal discount){
		this.quantity = quantity;
		this.discount = discount;
		description = item.getName();
		unitPrice = item.getPrice();
	}
	
	public int getQuantity() {
		return quantity;
	}
	
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
	
	public BigDecimal getUnitPrice() {
		return unitPrice;
	}
	
	public void setUnitPrice(BigDecimal unitPrice) {
		this.unitPrice = unitPrice;
	}
	
	public BigDecimal getDiscount() {
		return discount;
	}
	
	public void setDiscount(BigDecimal discount) {
		this.discount = discount;
	}
	
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@Override
	public String toString(){
		return getDescription() + "\t| " + 
				getQuantity() + "\t| " + 
				getUnitPrice().setScale(2, RoundingMode.CEILING) + "\t| " + 
				getDiscount().multiply(BigDecimal.valueOf(100)).setScale(1, RoundingMode.CEILING) + "%\t| " + 
				getFinalPrice().setScale(2, RoundingMode.CEILING) + "\n";
	}
	
	public BigDecimal getFinalPrice(){
		return Utils.CalculateDiscountedPrice(getUnitPrice(), getDiscount()).
				multiply(BigDecimal.valueOf(getQuantity()));
	}
}
